package day16;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.stream.Stream;

public class setPractice {
    public static void main(String[] args) {
        Set<String> set1=new HashSet<>();
        set1.add("西游记");
        set1.add("红楼梦");
        set1.add("水浒传");
        set1.add("三国演义");
        Set<String> set2=new HashSet<>();
        set2.add("红楼梦");
        System.out.println(set1);
        System.out.println(set1.contains("西游记"));//true
        System.out.println(set1.equals("红楼梦"));//false
        System.out.println(set1.hashCode());
        System.out.println(set1.isEmpty());//false
        System.out.println(set1.remove(null));//false
        System.out.println(set1.containsAll(set2));//true
        System.out.println(set1);
        System.out.println(set1.removeAll(set2));
        System.out.println(set1);
        System.out.println(set1.size());//3
        set1.addAll(set2);
        System.out.println(set1);
        Object[] array = set1.toArray();
        System.out.println(Arrays.toString(array));

        Set<String> set3=new HashSet<>();
        set3.add("小老鼠");
        set3.add("小老虎");
        set3.add("小乌龟");
        set3.add("小松鼠");
        System.out.println("***********");
        Stream<String> stream = set3.stream();
        System.out.println(stream);
        System.out.println(set1.addAll(set3));//true
        System.out.println(set1.containsAll(set3));//true
        System.out.println(set1.removeAll(set3));//true
        System.out.println(set1.containsAll(set3));//false
//        System.out.println(set1.retainAll(set3));//false

        Iterator<String> it = set1.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }

    }
}
